const puppeteer = require('puppeteer')

/**
 * 获取动态网页
 * @param { url } 目标网址
 * @returns { content } 网页内容
*/
async function getHTML (url) {
    const browser = await puppeteer.launch()
	const page = await browser.newPage()
    await page.setJavaScriptEnabled(true)
    await page.goto(url, { timeout: 0 })
    const content = await page.evaluate(() => {
		return {
            title: document.title,
			width: document.documentElement.clientWidth,
			height: document.documentElement.clientHeight,
            document: document.documentElement.innerHTML
		}
	})
	await browser.close()
    return content
}

module.exports = {
    getHTML
}
